package com.junsi.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
 * 行业管理控制器
 */
import org.springframework.web.servlet.ModelAndView;

import com.junsi.bean.Rank;
import com.junsi.bean.TradeManages;
import com.junsi.service.TradeManageService;

import net.sf.json.JSONArray;

@Controller
@RequestMapping("/tradeManage")
public class TradeManageController {
	@Autowired
	private TradeManageService tradeManageService;
	Logger logger = Logger.getRootLogger();

	/**
	 * 新增
	 */
	@RequestMapping("/insert")
	public ModelAndView insert(TradeManages tradeManage, HttpServletResponse response) throws Exception {
		tradeManageService.insert(tradeManage);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("redirect:/tradeManage/select.action");
		return modelAndView;
	}

	/**
	 * 刪除
	 */
	@RequestMapping("/deletes")
	public ModelAndView deletes(Integer id, HttpServletResponse response) {
		     tradeManageService.delete(id);
		  ModelAndView modelAndView=new ModelAndView();
		  modelAndView.setViewName("redirect:/tradeManage/select.action");
			return modelAndView;
	}

	/**
	 * 更新
	 * 
	 * @throws Exception
	 */
	@RequestMapping("/updata")
	public ModelAndView updata(TradeManages tradeManage, HttpServletResponse response) throws Exception {
		         tradeManageService.update(tradeManage);
		         ModelAndView modelAndView=new ModelAndView();
				  modelAndView.setViewName("redirect:/tradeManage/select.action");
					return modelAndView;
		
	}

	/**
	 * 查詢
	 * 
	 * @throws Exception
	 */
	@RequestMapping("/select")
	public ModelAndView select(HttpServletResponse response) throws Exception {
		List<TradeManages> list = tradeManageService.listAll();
		  ModelAndView modelAndView=new ModelAndView();
	      modelAndView.addObject("list", list);
	      modelAndView.setViewName("forward:/page/yewucanshu.jsp");
			return modelAndView;
	}

}
